/* 
  @project  intabs
  @name jquery.intabs.js
  @created  2008-11-11
  @version  0.2 (beta)
  @svn  http://intabs.googlecode.com/svn/trunk/
  @url  http://code.google.com/p/intabs
  @license  MIT License (http://www.opensource.org/licenses/mit-license.php)
  @author Lukasz Tyrala (http://lukasztyrala.pl/)
  @description  A jQuery Plugin for tabbed content browsing that needs no id only class names
  @contributors pblo, jan, adrian
*/

/*
  Basic step by step usage:
  
  1. Create xhtml that goes like this:
     [OPTIONAL] Add class "normal" to li that you do not want to be a tab
     
      <div class="your-container">

        <ul class="tabs">
          <li>[1]</li>
          <li>[2]</li>
          <li>[3]</li>
        </ul>

        <div class="tabbed"> [1] </div>
        <div class="tabbed"> [2] </div>
        <div class="tabbed"> [3] </div>

      </div> <-- /.your-cantainer -->

  2. Tell the plugin which elements are containers for tabbed content:
  
      $('your-container').intabs();

  3. Enjoy!
     [OPTIONAL] If not (a) try to improve by yourself, (b) give me a feedback

*/

;jQuery(function($) {

  ;(function($) {
    jQuery.fn.intabs = function(tab_id) {

      return this.each(function() {

        var start_tab       = tab_id || 0; // Tab index to start from

        // Settings ----------------------------
        var nav_element_def = '.tabs li'; // Avoid using class names for li as they are destroyed while changing a tab
        var sub_section_def = '.tabbed';
        var normal_def      = '.normal';
        var current_label   = 'current';
        // End od settings ---------------------

        var nav_element = $(this).find(nav_element_def).not(normal_def);
        var sub_section = $(this).find(sub_section_def);

        var sub_section_start = sub_section.eq(start_tab);
        var nav_element_start = nav_element.eq(start_tab);

        sub_section.hide();
        sub_section_start.show();
        nav_element.addClass('');
        nav_element_start.addClass(current_label);

        // Change 'click' to eg. 'mouseover' for different event
        nav_element.click(function() {
          var nav_index = nav_element.index(this);

          // @todo Give user possibility to choose effects
          sub_section.hide();
          sub_section.eq(nav_index).show();

          nav_element.removeAttr('class');
          nav_element.eq(nav_index).addClass(current_label);
          return false;
         });
       });


    };                        // /jQuery.fn.intabs = function() {

  })(jQuery);                 // /function($) {

});                           // /jQuery(function($) {
